home *** CD-ROM | disk | FTP | other *** search
/ Merciful 1 / Merciful - Disc 1.iso / software / g / gvp_faaast_prep / gvpfaastprep.dms / gvpfaastprep.adf / ScsiExamples / ScsiExamples.lzh / ReadSector.c < prev    next >
C/C++ Source or Header  |  1990-07-15  |  3KB  |  119 lines

  1. /*
  2. ** ReadSector.c - read a sector using GVP's SCSI device driver
  3. ** Copyright (C) 1990 by Ralph Babel, Falkenweg 3, D-6204 Taunusstein, FRG
  4. ** all rights reserved - alle Rechte vorbehalten
  5. **
  6. ** 03-Jun-1990 created
  7. */
  8.  
  9. /*** included files ***/
  10.  
  11. #include <exec/types.h>
  12. #include <exec/memory.h>
  13. #include <devices/trackdisk.h>
  14. #include <libraries/dos.h>
  15. #include <proto/exec.h>
  16. #include <proto/dos.h>
  17. #include <string.h>
  18.  
  19. /*** external symbol references ***/
  20.  
  21. void sprintf(char *, const char *, ...);
  22. void fprintf(BPTR, const char *, ...);
  23.  
  24. /*** constants ***/
  25.  
  26. #define BOARD 0 /* controller board */
  27. #define TID   0 /* SCSI target ID */
  28. #define LUN   0 /* logical unit */
  29.  
  30. #define UNIT (BOARD * 100 + LUN * 10 + TID)
  31.  
  32. /*** entry point (RXStartUp.obj) ***/
  33.  
  34. void __stdargs __saveds main(
  35. ULONG argc,
  36. const char *const argv[])
  37.  {
  38.  BPTR fh;
  39.  char *s;
  40.  UBYTE *p;
  41.  UBYTE *data;
  42.  struct MsgPort *mp;
  43.  struct IOStdReq *io;
  44.  UWORD i, j;
  45.  UBYTE d;
  46.  char buffer[80];
  47.  
  48.  if(argc != 0) /* CLI only! */
  49.   {
  50.   fh = Output();
  51.  
  52.   if((data = AllocMem(TD_SECTOR, MEMF_CHIP)) != NULL)
  53.    {
  54.    if((mp = CreatePort(NULL, 0)) != NULL)
  55.     {
  56.     if((io = CreateStdIO(mp)) != NULL)
  57.      {
  58.      if(OpenDevice("gvpscsi.device", UNIT, (struct IORequest *)io, 0) == 0)
  59.       {
  60.       io->io_Command = CMD_READ;
  61.       io->io_Length  = TD_SECTOR;
  62.       io->io_Data    = (APTR)data;
  63.       io->io_Offset  = 0 * TD_SECTOR; /* sector offset */
  64.  
  65.       (void)DoIO((struct IORequest *)io);
  66.  
  67.       fprintf(fh, "io_Error = %d\n", io->io_Error);
  68.  
  69.       if(io->io_Error == 0)
  70.        {
  71.        fprintf(fh, "\n");
  72.  
  73.        buffer[70] = '\0';
  74.  
  75.        for(p = data, i = 0; i < TD_SECTOR; i += 16)
  76.         {
  77.         sprintf(buffer, "%03x:", i);
  78.         (void)memset(buffer + 4, ' ', 66);
  79.  
  80.         for(s = buffer + 4, j = 0; j < 16; s += 3, ++j)
  81.          {
  82.          sprintf(s, " %02x", d = *p++);
  83.          buffer[53 + j] = d >= 32 && d <= 126 || d >= 160? d: '.';
  84.          }
  85.  
  86.         *s = ' ';
  87.         fprintf(fh, "%s\n", buffer);
  88.         }
  89.        }
  90.  
  91.       /* make ALWAYS sure the motor is turned off! */
  92.  
  93.       io->io_Command = TD_MOTOR;
  94.       io->io_Length  = 0;
  95.       (void)DoIO((struct IORequest *)io);
  96.  
  97.       CloseDevice((struct IORequest *)io);
  98.       }
  99.      else
  100.       fprintf(fh, "Error %d while opening SCSI unit %ld.\n",
  101.        io->io_Error, (long)UNIT);
  102.  
  103.      DeleteStdIO(io);
  104.      }
  105.     else
  106.      fprintf(fh, "Could not create I/O request.\n");
  107.  
  108.     DeletePort(mp);
  109.     }
  110.    else
  111.     fprintf(fh, "Could not create message port.\n");
  112.  
  113.    FreeMem(data, TD_SECTOR);
  114.    }
  115.   else
  116.    fprintf(fh, "Insufficient free store.\n");
  117.   }
  118.  }
  119.